package com.example.demo;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

@RequestMapping("/book")
@RestController
public class BookControl {
    @RequestMapping("/getBookList")
 public List<BookInfo> getBook(){
      List<BookInfo> list = mockData();
      for(BookInfo bookInfo:list){
          if(bookInfo.getStatus()==1){
              bookInfo.setStatusCN("可借阅");
          }else{
              bookInfo.setStatusCN("不可借阅");
          }

      }
      return list;
 }
public List<BookInfo> mockData(){
        List<BookInfo> list = new ArrayList<>(15);
        for(int i=0;i<15;i++){
            BookInfo bookInfo = new BookInfo();
            bookInfo.setId(i);
            bookInfo.setBookName("巴拉啦小魔仙"+i);
            bookInfo.setAuthor("三梦奇缘"+i);
            bookInfo.setCount(new Random().nextInt(1000));
            bookInfo.setPrice(new BigDecimal(new Random().nextInt(200)));
            bookInfo.setPublish("三梦奇缘出版社"+i);
            bookInfo.setStatus(i%5==0?2:1);
              list.add(bookInfo);
        }
        return list;
}
}
